import request from "../../utils/request";

// 任务状态枚举
export enum TaskStatus {
    PENDING = 0,    // 待处理
    PROCESSING = 1, // 处理中
    COMPLETED = 2,  // 已完成
    FAILED = 3      // 失败
}

// 任务队列响应对象
export interface TaskQueueResponseVO {
    taskId: number;
    userId: number;
    taskType: string;
    inputData: any;
    status: number;
    progress: number;
    resultUrl?: string;
    createdAt: string;
    updatedAt: string;
}

// 分页数据接口
interface PageData<T> {
    records: T[];
    total: number;
    size: number;
    current: number;
    pages: number;
}

// API 通用响应格式
interface BaseResponse<T> {
    code: number;
    message: string;
    data: T;
}

// 任务分页数据响应
type TaskPageResponse = BaseResponse<PageData<TaskQueueResponseVO>>;

export const taskApi = {
    getTasksByPage: async (params: {
        current?: number;
        pageSize?: number;
        status?: number;
        taskType?: string;
        userId?: number;
    }) => {
        return request.get<TaskPageResponse>('/api/tasks/page', {
            params: {
                current: params.current || 1,
                pageSize: params.pageSize || 10,
                ...params
            }
        });
    }
};
